// POP UP
function InsertFromPopUp(name, id, choosed_name, choosed_id) {
	
	var name = window.opener.document.getElementById(name);
	var id = window.opener.document.getElementById(id);
	
	//var msg = "Patient: "+patient_name+"\n";
	//msg += "Choose this patient and close the window?";
	
	//if(window.confirm(msg)) { 
		name.value = choosed_name;
		id.value = choosed_id;
		window.close(); 
	//}
}


function OpenPopup(page, field_name, field_id) {	
	OpenWin(page+'&field_name='+field_name+'&field_id='+field_id+'&popup=1', 'popup', '750', '500', 'yes', false, false);		
}


// we use it when pop up, to empty field
function doEmpty() {
	var field;
	for(i=0;i<arguments.length;i++){
		field = document.getElementById(arguments[i]);
		field.value = '';
	}
}


// reapet html	
function getMoreHtml() {
	
	this.readroot = 'readroot';
	this.writeroot = 'writeroot';
	this.counter = 0;
	this.id_pref = 'more_html_';
	this.confirm_use = false; //alert to close window
	this.confirm_msg = '';
	//this.id_tag = 'INPUT';
	//this.value_tag = 'SPAN';
	
	
	this.get = function(id_value, name_value) {
	    
		this.counter++;
		
		var readBlock = this.getDivObject(this.readroot).cloneNode(true);
		readBlock.id = '';
		readBlock.style.display = 'block';
		var newBlock = readBlock.childNodes; // div 
		
		for (var i=0;i<newBlock.length;i++) {
			
			if (newBlock[i].id) {
				newBlock[i].id = this.id_pref + this.counter; // div id that = d
				
				// to switch to other div (inner) we add  [1].childNodes;
				var newBlockContent = newBlock[i].childNodes[1].childNodes;				
				
				for (var j=0;j<newBlockContent.length;j++) {
					
					if(newBlockContent[j].tagName == 'INPUT') {
						newBlockContent[j].value = id_value; // hidden id
					}
					
					if(newBlockContent[j].tagName == 'SPAN') {
						newBlockContent[j].firstChild.nodeValue = name_value; // value
					}
				}
			}
		}
		
		var insertBlock = this.getDivObject(this.writeroot);
		insertBlock.parentNode.insertBefore(readBlock,insertBlock);
		
		if(this.confirm_use) {
			this.confirmAction();
		}
	}
	
	
	this.confirmAction = function() {
	
		ret = confirm(this.confirm_msg);
		if(!ret) {
			window.close();
		}
	}
	
	
	this.remove = function(obj) {
		obj.parentNode.parentNode.removeChild(obj.parentNode);
	}
	
	this.getDivObject = function(div_obj) {
		if(typeof(div_obj) == 'object') {
			 return div_obj;
		} else {
			return document.getElementById(div_obj);
		}
	}
}


function removeHtml(obj) {
	//alert(obj.parentNode.parentNode.id);
	alert(obj.parentNode.parentNode.id);
	obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
}

/*
function removeHtml(obj) {
	alert(obj.parentNode.parentNode);
	obj.parentNode.parentNode.removeChild(obj.parentNode);
}
*/

//s = new getMoreHtml();
//s.writeroot = document.getElementById('writeroot');